<template>
  <div class="buy">
    <header>
      <div class="header-one">
        <span @click="goback">
          <van-icon name="arrow-left" />
        </span>
        <span>价格筛选</span>
        <span>
          <van-icon name="more-o" />
        </span>
      </div>
      <div class="header-two">
        <div class="search">
          <div class="option">
            <span @click="anchor">
              北京
              <a-icon type="caret-down" />
            </span>
          </div>
          <div class="input">
            <input type="text" placeholder="请在这里输入区域/商圈" />
            <van-icon name="search" class="icon" />
          </div>
          <span>地图找房</span>
        </div>
      </div>
      <div class="header-three">
        <li>
          <select v-model="select" @change="area(select)">
            <option v-for="(item,index) in option" :key="index">{{item.text}}</option>
          </select>
        </li>
        <li>
          <select v-model="select1">
            <option v-for="(item,index) in option1" :key="index">{{item}}</option>
          </select>
        </li>
        <li>
          <select v-model="select2" @change="area2(select2)">
            <option v-for="(item,index) in option2" :key="index">{{item.text}}</option>
          </select>
        </li>
        <li>
          <select v-model="select3" @change="area3(select3)">
            <option v-for="(item,index) in option3" :key="index">{{item.text}}</option>
          </select>
        </li>
        <li>
          <i class="el-icon-sort-down" @click="rank()"></i>
          <i class="el-icon-sort-up" @click="rank1()"></i>
        </li>
      </div>
    </header>
    <main>
      <div class="main">
        <!-- <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <van-cell > -->
              <div class="detail" v-for="(item,index) in list" :key="index">
                <img :src="item.img1" alt @click="detail(item.id)" />
                <div class="main-one">
                  <p>{{item.word}}</p>
                  <p>
                    <span>{{item.cityone}}</span>&emsp;
                    <span>{{item.housescreen}}</span>&emsp;
                    <span>{{item.senscs}}</span>
                  </p>
                  <p>
                    <span class="price">{{item.price}}万</span>&emsp;
                    <span class="money">12100元/m²</span>
                  </p>
                  <p>
                    <button>小区</button>
                  </p>
                </div>
              </div>
        <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
          <div class="main_list" v-for="(item,index) in list" :key="index">
            <div class="detail">
              <img :src="item.img" alt @click="detail(item.id)" />
              <div class="main-one">
                <p>{{item.title}}</p>
                <p>
                  <span>{{item.type}}</span>&emsp;
                  <span>{{item.citys}}</span>&emsp;
                  <span>{{item.screen}}</span>
                </p>
                <p>
                  <span class="price">{{item.price}}万</span>&emsp;
                  <span class="money">12100元/m²</span>
                </p>
                <p>
                  <button>小区</button>
                </p>
              </div>
            </div>
          </div>
        </van-pull-refresh>-->
      </div>
    </main>
  </div>
</template>

<script>
import { Toast } from "vant";
import axios from "axios";
export default {
  data() {
    return {
      select: "区域",
      option: [
        { text: "区域", value: "区域" },
        { text: "附近", value: "附近" },
        { text: "地铁", value: "地铁" },
        { text: "上海", value: "上海" },
        { text: "北京", value: "北京" },
        { text: "江苏", value: "江苏" }
      ],
      list: [],
      count: 0,
      isLoading: false,
      loading: false,
      finished: false,
      refreshing: false,
      select1: "价格",
      option1: [
        "价格",
        "不限",
        "≤10万",
        "20万-30万",
        "30万-50万",
        "50万-100万",
        "≥1000万"
      ],
      select2: "户型",
      option2: [
        { text: "户型", value: "户型" },
        { text: "不限", value: "不限" },
        { text: "新房", value: "新房" },
        { text: "二手房", value: "二手房" },
        { text: "不限", value: "不限" },
        { text: "1室", value: "1室" },
        { text: "2室", value: "2室" },
        { text: "3室", value: "3室" },
        { text: "4室", value: "4室" }
      ],
      select3: "筛选",
      option3: [
        { text: "筛选", value: "筛选" },
        { text: "不限", value: "不限" },
        { text: "安选", value: "安选" },
        { text: "南北", value: "南北" },
        { text: "东", value: "东" },
        { text: "西", value: "西" },
        { text: "南", value: "南" },
        { text: "北", value: "北" }
      ]
    };
  },
  created() {
    this.getlist();
  },
  methods: {
    //返回上一页
    goback() {
      this.$router.go(-1);
    },
    //获取数据
    getlist() {
      axios({
        url: "/api/lists",
        method: "get"
      }).then(res => {
        this.list = res.data.data;
      });
    },

    // //下拉刷新
    // onRefresh() {
    //   setTimeout(() => {
    //     Toast("刷新成功");
    //     this.isLoading = false;
    //   }, 500);
    // },
    //跳转到描点
    anchor() {
      this.$router.push("/anchor");
    },
    //跳转详情
    detail(id) {
      this.$router.push(`/detail/` + id);
    },
    area(select) {
      axios({
        url: "/api/area",
        method: "post",
        data: {
          select: select
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },
    area2(select2) {
      axios({
        url: "/api/area2",
        method: "post",
        data: {
          select2: select2
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },

    area3(select3) {
      axios({
        url: "/api/area3",
        method: "post",
        data: {
          select3: select3
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },
    rank() {
      this.list.sort((a, b) => {
        return a.price - b.price;
      });
    },
    rank1() {
      this.list.sort((a, b) => {
        return b.price - a.price;
      });
    },
    // async onLoad() {
    //   let res = await axios.get("/api/getlist");
    //   setTimeout(() => {
    //     if (this.refreshing) {
    //       this.getlist = [];
    //       this.refreshing = false;
    //     }
    //     for (let i = 0; i < 10; i++) {
    //       this.list.push(this.list.length + 1);
    //     }
    //     this.loading = false;

    //     if (this.getlist.length >= 20) {
    //       this.finished = true;
    //     }
    //   }, 1000);
    // },
    // onRefresh() {
    //   // 清空列表数据
    //   this.finished = false;

    //   // 重新加载数据
    //   // 将 loading 设置为 true，表示处于加载状态
    //   this.loading = true;
    //   this.onLoad();
    // }
  }
};
</script>

<style scoped>
.buy {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.detail img{
  width: 150px;
  height: 120px;
}
header {
  height: 241px;
  border-bottom: 1px solid #cccccc;
}
main {
  flex: 1;
  overflow-y: auto;
}
.header-one {
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 30px;
  font-size: 22px;
  color: #f3f9ff;
  content: "";
  background: linear-gradient(45deg, #0f7ef4, #1988f6, #34a0fd);
}
.header-two {
  height: 75px;

}
.search {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 10px;
  border-bottom: 1px solid #cccccc;
  color: #9b9b9b;
}
.header-three {
  display: flex;
  height: 59px;
  align-items: center;
  justify-content: space-between;
  padding: 0px 30px;
  color: #999999;
}
.option select {
  background: none;
  border: none;
  outline: none;
}
.option select option {
  background: #82b9f3;
}
.input {
  width: 200px;
  height: 30px;
  border: 1px solid #cccccc;
  display: inline-block;
  background: #f4f4f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input span {
  color: #929292;
}
.input input {
  border: none;
  background: none;
  outline: none;
}
.input .icon {
  color: #9c9c9c;
  font-weight: bold;
  font-size: 20px;
}
/* .hint {
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 20px;
} */
.detail {
  display: flex;
  margin: 10px;
}
.main-one {
  margin-left: 10px;
}
.main-one button {
  width: 50px;
  height: 20px;
  border: none;
}
.price {
  color: orange;
  font-weight: bold;
}
</style>